<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{{.Title}}</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdn.bootcss.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
    <script src="https://cdn.bootcss.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
    <script src="/statics/js/jquery.json.min.js"></script>
    <script src="/statics/layer/layer.js"></script>
    <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<div class="container-fluid  center-block" style="margin-top: 30px;margin-bottom: 30px">
    <form autocomplete="off">
        <div class="form-group">
            <div class="input-group">
                <span class="input-group-addon">任务名称</span>
                <input type="text" class="form-control " {{if eq .Body.type 1}}readonly{{end}} autocomplete="off" {{if eq .Body.type 1}}value="{{.Body.data.Name}}"{{end}} id="job_name" name="edit_name" placeholder="输入任务名称">
                {{if eq .Body.type 0}}
                <span class="input-group-btn" >
                    <button type="button" onclick="checkJobName()" class="btn btn-success"><span class="glyphicon glyphicon-refresh"></span> </button>
                </span>
                {{end}}

            </div>
        </div>
        <div class="form-group">
            <div class="input-group">
                <span class="input-group-addon">运行目录</span>
                <input type="text" class="form-control" autocomplete="off" {{if eq .Body.type 1}}value="{{.Body.data.RunDir}}"{{end}} id="run_dir" name="edit_pwd" placeholder="输入运行日志文件的名字（含路径）">
            </div>
        </div>
        <div class="form-group">
            <div class="input-group">
                <span class="input-group-addon">运行命令</span>
                <input type="text" class="form-control" autocomplete="off" {{if eq .Body.type 1}}value="{{.Body.data.RunCmd}}"{{end}} id="run_cmd" name="edit_pwd" placeholder="输入启动任务的命令">
                <span class="input-group-addon">命令参数</span>
                <input type="text" class="form-control" autocomplete="off" {{if eq .Body.type 1}}value="{{.Body.data.RunCmdExt}}"{{end}} id="run_cmd_ext" name="edit_pwd" placeholder="输入启动任务的命令参数">
            </div>
        </div>
        <div class="form-group">
            <div class="input-group">
                <span class="input-group-addon">运行日志</span>
                <input type="text" class="form-control" autocomplete="off" {{if eq .Body.type 1}}value="{{.Body.data.RunLog}}"{{end}} id="run_log" name="edit_pwd" placeholder="输入运行日志文件的名字（含路径）">
            </div>
        </div>
        <div class="form-group">
            <div class="input-group">
                <span class="input-group-addon">Hook目录</span>
                <input type="text" class="form-control" autocomplete="off" {{if eq .Body.type 1}}value="{{.Body.data.HookDir}}"{{end}} id="hook_dir" name="edit_pwd" placeholder="输入运行日志文件的名字（含路径）">
            </div>
        </div>
        <div class="form-group">
            <div class="input-group">
                <span class="input-group-addon">Hook命令</span>
                <input type="text" class="form-control" autocomplete="off" {{if eq .Body.type 1}}value="{{.Body.data.HookCmd}}"{{end}} id="hook_cmd" name="edit_pwd" placeholder="输入Hook命令">
                <span class="input-group-addon">命令参数</span>
                <input type="text" class="form-control" autocomplete="off" {{if eq .Body.type 1}}value="{{.Body.data.HookCmdExt}}"{{end}} id="hook_cmd_ext" name="edit_pwd" placeholder="输入Hook命令的参数">
            </div>
        </div>
        <div class="form-group">
            <div class="input-group">
                <span class="input-group-addon">Hook日志</span>
                <input type="text" class="form-control" autocomplete="off" {{if eq .Body.type 1}}value="{{.Body.data.HookLog}}"{{end}} id="hook_log" name="edit_pwd" placeholder="输入Hook日志文件的名称">
            </div>
        </div>

        <button type="button" id="submit" style="width: 390px;" class="btn btn-primary center-block" onclick="saveJob()">提交</button>
    </form>

</div>
</body>
<script type="application/javascript">
    var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
    parent.layer.iframeAuto(index);
    {{if eq .Body.type 1}}
        $("#submit").show()
    {{else}}
        $("#submit").hide()
    {{end}}

    $('#job_name').bind('input propertychange', function() {
        $("#submit").hide()
        parent.layer.iframeAuto(index);
    });
    function checkJobName() {
        name=$("#job_name").val();
        $.ajax({
            url: "/checkJobName",
            data: $.toJSON({name:name}),
            type: 'POST',
            dataType: "JSON",
            success: function(data){
                parent.layer.msg(data.msg);
                if(data.code==0){
                    $("#submit").show()
                }else{
                    $("#submit").hide()
                }
                parent.layer.iframeAuto(index);
            }
        })
    }
    function saveJob(){
        name=$("#job_name").val();
        run_dir=$("#run_dir").val();
        run_cmd=$("#run_cmd").val();
        run_cmd_ext=$("#run_cmd_ext").val();
        run_log=$("#run_log").val();
        hook_dir=$("#hook_dir").val();
        hook_cmd=$("#hook_cmd").val();
        hook_cmd_ext=$("#hook_cmd_ext").val();
        hook_log=$("#hook_log").val();
        $.ajax({
            url: "/jobInfo",
            data: $.toJSON(
                {
                    name:name,
                    run_dir:run_dir,
                    run_cmd:run_cmd,
                    run_cmd_ext:run_cmd_ext,
                    run_log:run_log,
                    hook_dir:hook_dir,
                    hook_cmd:hook_cmd,
                    hook_cmd_ext:hook_cmd_ext,
                    hook_log:hook_log
                }),
            type: 'POST',
            dataType: "JSON",
            success: function(data){
                parent.layer.msg(data.msg);
                parent.layer.close(index);
                parent.location.reload(true);
            }
        })
    }

</script>
</html>